﻿using System;
using System.Collections.Generic;
using System.Web;
using DAL;
using Model;
using System.Data;
namespace BLL
{
    /// <summary>
    /// 庭室数据服务中心
    /// </summary>
    public class DepartmentService
    {
        /// <summary>
        /// 根据法院代码获取该法院下的庭室。
        /// </summary>
        public static Obj_B_TSJG[] GetDepartments(string fydm)
        {
            Obj_B_TSJG[] departments = new Obj_B_TSJG[0];
         
                string conStr = DBConnector.GetConnectString(fydm);
                string selectStr = string.Format("select * from {0} where  sftjflag=1  and mc not like '%院领导%' and fy={1} order by mc", Obj_B_TSJG.TableName, fydm);
                DataTable dt = DBConnector.GetSqlSelectData(selectStr, conStr);
                if (dt != null && dt.Rows.Count > 0)
                {
                    int count =dt.Rows.Count;
                    departments = new Obj_B_TSJG[count];
                    for (int i = 0; i < count; i++)
                    {
                        departments[i]= new Obj_B_TSJG(dt.Rows[i]);
                    }  
                }
                return departments;
        }

        /// <summary>
        /// 根据庭室代码获取参数法院下的庭室对象。
        /// </summary>
        public static Obj_B_TSJG GetDepartment(string fydm,string tsdm)
        {
            Obj_B_TSJG department = null;

            string conStr = DBConnector.GetConnectString(fydm);
            string selectStr = string.Format("select * from {0} where sftjflag=1 and mc not like '%院领导%' and fy={1} and xh={2}", Obj_B_TSJG.TableName, fydm, tsdm);
            DataTable dt = DBConnector.GetSqlSelectData(selectStr, conStr);
            if (dt != null && dt.Rows.Count > 0)
            {
                    department = new Obj_B_TSJG(dt.Rows[0]);
            }
            return department;
        }
 
    }
}
